-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: allow timestamps and overwriteImmutable in TS and JS for 7.x #15820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: vkarpov15/gh-15782
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds per-operation timestamps support for insertOne and replaceOne in bulkWrite operations, along with comprehensive TypeScript type definitions for all bulkWrite operation types.
Key changes:
- Introduced Mongoose-specific TypeScript types for bulkWrite operations that extend MongoDB driver functionality with options like
timestamps,overwriteImmutable,setDefaultsOnInsert, andskipValidation - Implemented
getTimestampsOpthelper to support per-operation timestamp control with proper precedence (operation-level > bulkWrite-level > default) - Added thorough test coverage for both JavaScript and TypeScript
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| types/models.d.ts | Added custom TypeScript types for bulkWrite operations including AnyBulkWriteOperation, InsertOneModel, ReplaceOneModel, UpdateOneModel, UpdateManyModel, DeleteOneModel, and DeleteManyModel with Mongoose-specific options |
| test/types/models.test.ts | Added TypeScript test gh15781 verifying type safety for timestamps and overwriteImmutable options on UpdateOneModel and UpdateManyModel; updated imports to distinguish between Mongoose and MongoDB driver types |
| test/model.test.js | Added two comprehensive tests verifying per-operation timestamps functionality for insertOne and replaceOne operations with both timestamps: false and timestamps: true override scenarios |
| lib/helpers/model/castBulkWrite.js | Implemented getTimestampsOpt helper function and integrated it into insertOne and replaceOne operations to support per-operation timestamp control |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
vkarpov15
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a couple of minor comments
|
@vkarpov15 The original solution required |
…without overwriteImmutable: true
PR Summary
Add TypeScript types and per-operation timestamps support for bulkWrite (gh-15782)
AnyBulkWriteOperationtype withtimestamps,overwriteImmutable,setDefaultsOnInsert, andskipValidationoptionstimestamps: falseto be able to update timestamps withoverwriteImmutable.